package com.longcai.piaojia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.LatestListGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by shenyuxin on 2017/1/8.
 */
public class LatestAdapter extends ArrayAdapter<LatestListGet.Latest> {

    private Context context;
    private LayoutInflater layoutInflater;
    public LatestAdapter(Context context, List<LatestListGet.Latest> lists) {
        super(context, 0, lists);

        this.context = context;

        layoutInflater = LayoutInflater.from(context);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LatestListGet.Latest latest = getItem(position);

        ViewHodler viewHodler;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHodler = new ViewHodler(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_latest_list, null)));

            convertView.setTag(viewHodler);
        } else {

            viewHodler = (ViewHodler) convertView.getTag();
        }

        GlideLoader.getInstance().get(context, latest.picurl, viewHodler.item_latest_iv, R.mipmap.home_center);

        return convertView;
    }

    class ViewHodler {

        @BoundView(R.id.item_latest_iv) private ImageView item_latest_iv;


    }
}
